package li.webqq.util;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author 明伟
 */
public class MapUtil {
    public static <T> T parse(Class<T> type, Map map) {
        return parse(ReflectUtil.born(type), map);
    }

    public static <T> T parse(T model, Map map) {
        for (Object each : map.entrySet()) {
            Entry entry = (Entry) each;
            Field field = ReflectUtil.getField(model.getClass(), entry.getKey() + "");
            if (null != field) {
                ReflectUtil.set(model, field, entry.getValue());
            }
        }
        return model;
    }
}